package com.aacar.op.utils.pojo.datatables;


import com.github.pagehelper.PageInfo;
import org.springframework.data.domain.Page;

import java.io.Serializable;
import java.util.List;

public class DataTablesResult<T> implements Serializable {
    //    private Long draw;
    private Long recordsTotal;
    private Long recordsFiltered;
    private List<T> data;

    public static <T> DataTablesResult build(Page<T> page) {
        return new DataTablesResult(page);
    }

    public static <T> DataTablesResult build(PageInfo<T> pageInfo) {
        return new DataTablesResult(pageInfo);
    }

    public DataTablesResult(Page<T> page) {
        this.data = page.getContent();
        this.recordsTotal = page.getTotalElements();
        this.recordsFiltered = page.getTotalElements();
    }

    public DataTablesResult(PageInfo<T> pageInfo) {
        this.data = pageInfo.getList();
        this.recordsTotal = pageInfo.getTotal();
        this.recordsFiltered = pageInfo.getTotal();
    }


    public Long getRecordsTotal() {
        return recordsTotal;
    }

    public void setRecordsTotal(Long recordsTotal) {
        this.recordsTotal = recordsTotal;
    }

    public Long getRecordsFiltered() {
        return recordsFiltered;
    }

    public void setRecordsFiltered(Long recordsFiltered) {
        this.recordsFiltered = recordsFiltered;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }
}
